home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / kmdcodec.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-10-10  |  21.1 KB  |  746 lines

  1. /*
  2.    Copyright (C) 2000-2001 Dawit Alemayehu <adawit@kde.org>
  3.    Copyright (C) 2001 Rik Hemsley (rikkus) <rik@kde.org>
  4.  
  5.    This program is free software; you can redistribute it and/or modify
  6.    it under the terms of the GNU Lesser General Public License (LGPL)
  7.    version 2 as published by the Free Software Foundation.
  8.  
  9.    This program is distributed in the hope that it will be useful,
  10.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.    GNU General Public License for more details.
  13.  
  14.    You should have received a copy of the GNU Library General Public
  15.    License along with this program; if not, write to the Free Software
  16.    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  17.  
  18.    RFC 1321 "MD5 Message-Digest Algorithm" Copyright (C) 1991-1992.
  19.    RSA Data Security, Inc. Created 1991. All rights reserved.
  20.  
  21.    The KMD5 class is based on a C++ implementation of
  22.    "RSA Data Security, Inc. MD5 Message-Digest Algorithm" by
  23.    Mordechai T. Abzug,    Copyright (c) 1995.  This implementation
  24.    passes the test-suite as defined in RFC 1321.
  25.  
  26.    The encoding and decoding utilities in KCodecs with the exception of
  27.    quoted-printable are based on the java implementation in HTTPClient
  28.    package by Ronald TschalΣr Copyright (C) 1996-1999.
  29.  
  30.    The quoted-printable codec as described in RFC 2045, section 6.7. is by
  31.    Rik Hemsley (C) 2001.
  32. */
  33.  
  34. #ifndef _KMDBASE_H
  35. #define _KMDBASE_H
  36.  
  37. #define KBase64 KCodecs
  38.  
  39. #include <qglobal.h>
  40. #include <qstring.h>
  41. #include <qiodevice.h>
  42. #include "kdelibs_export.h"
  43.  
  44. /**
  45.  * A wrapper class for the most commonly used encoding and
  46.  * decoding algorithms.  Currently there is support for encoding
  47.  * and decoding input using base64, uu and the quoted-printable
  48.  * specifications.
  49.  *
  50.  * \b Usage:
  51.  *
  52.  * \code
  53.  * QCString input = "Aladdin:open sesame";
  54.  * QCString result = KCodecs::base64Encode(input);
  55.  * cout << "Result: " << result.data() << endl;
  56.  * \endcode
  57.  *
  58.  * <pre>
  59.  * Output should be
  60.  * Result: QWxhZGRpbjpvcGVuIHNlc2FtZQ==
  61.  * </pre>
  62.  *
  63.  * The above example makes use of the convenience functions
  64.  * (ones that accept/return null-terminated strings) to encode/decode
  65.  * a string.  If what you need is to encode or decode binary data, then
  66.  * it is highly recommended that you use the functions that take an input
  67.  * and output QByteArray as arguments.  These functions are specifically
  68.  * tailored for encoding and decoding binary data.
  69.  *
  70.  * @short A collection of commonly used encoding and decoding algorithms.
  71.  * @author Dawit Alemayehu <adawit@kde.org>
  72.  * @author Rik Hemsley <rik@kde.org>
  73.  */
  74. class KDECORE_EXPORT KCodecs
  75. {
  76. public:
  77.  
  78.   /**
  79.    * Encodes the given data using the quoted-printable algorithm.
  80.    *
  81.    * @param in      data to be encoded.
  82.    * @param useCRLF if true the input data is expected to have
  83.    *                CRLF line breaks and the output will have CRLF line
  84.    *                breaks, too.
  85.    * @return        quoted-printable encoded string.
  86.    */
  87.   static QCString quotedPrintableEncode(const QByteArray & in,
  88.                                         bool useCRLF = true);
  89.  
  90.   /**
  91.    * @overload
  92.    *
  93.    * Same as above except it accepts a null terminated
  94.    * string instead an array.
  95.    *
  96.    * @param str     string to be encoded.
  97.    * @param useCRLF if true the input data is expected to have
  98.    *                CRLF line breaks and the output will have CRLF line
  99.    *                breaks, too.
  100.    * @return        quoted-printable encoded string.
  101.    */
  102.   static QCString quotedPrintableEncode(const QCString & str,
  103.                                         bool useCRLF = true);
  104.  
  105.   /**
  106.    * Encodes the given data using the quoted-printable algorithm.
  107.    *
  108.    * Use this function if you want the result of the encoding
  109.    * to be placed in another array which cuts down the number
  110.    * of copy operation that have to be performed in the process.
  111.    * This is also the preferred method for encoding binary data.
  112.    *
  113.    * NOTE: the output array is first reset and then resized
  114.    * appropriately before use, hence, all data stored in the
  115.    * output array will be lost.
  116.    *
  117.    * @param in      data to be encoded.
  118.    * @param out     encoded data.
  119.    * @param useCRLF if true the input data is expected to have
  120.    *                CRLF line breaks and the output will have CRLF line
  121.    *                breaks, too.
  122.    */
  123.   static void quotedPrintableEncode(const QByteArray & in, QByteArray& out,
  124.                                     bool useCRLF);
  125.  
  126.   /**
  127.    * Decodes a quoted-printable encoded data.
  128.    *
  129.    * Accepts data with CRLF or standard unix line breaks.
  130.    *
  131.    * @param in  data to be decoded.
  132.    * @return    decoded string.
  133.    */
  134.   static QCString quotedPrintableDecode(const QByteArray & in);
  135.  
  136.   /**
  137.    * @overload
  138.    *
  139.    * Same as above except it accepts a null terminated
  140.    * string instead an array.
  141.    *
  142.    * @param str  string to be decoded.
  143.    * @return     decoded string.
  144.    */
  145.   static QCString quotedPrintableDecode(const QCString & str);
  146.  
  147.   /**
  148.    * Decodes a quoted-printable encoded data.
  149.    *
  150.    * Accepts data with CRLF or standard unix line breaks.
  151.    * Use this function if you want the result of the decoding
  152.    * to be placed in another array which cuts down the number
  153.    * of copy operation that have to be performed in the process.
  154.    * This is also the preferred method for decoding an encoded
  155.    * binary data.
  156.    *
  157.    * NOTE: the output array is first reset and then resized
  158.    * appropriately before use, hence, all data stored in the
  159.    * output array will be lost.
  160.    *
  161.    * @param in   data to be decoded.
  162.    * @param out  decoded data.
  163.    */
  164.   static void quotedPrintableDecode(const QByteArray & in, QByteArray& out);
  165.  
  166.  
  167.   /**
  168.    * Encodes the given data using the uuencode algorithm.
  169.    *
  170.    * The output is split into lines starting with the number of
  171.    * encoded octets in the line and ending with a newline.  No
  172.    * line is longer than 45 octets (60 characters), excluding the
  173.    * line terminator.
  174.    *
  175.    * @param in   data to be uuencoded
  176.    * @return     uuencoded string.
  177.    */
  178.   static QCString uuencode( const QByteArray& in );
  179.  
  180.   /**
  181.    * @overload
  182.    *
  183.    * Same as the above functions except it accepts
  184.    * a null terminated string instead an array.
  185.    *
  186.    * @param str   string to be uuencoded.
  187.    * @return      encoded string.
  188.    */
  189.   static QCString uuencode( const QCString& str );
  190.  
  191.   /**
  192.    * Encodes the given data using the uuencode algorithm.
  193.    *
  194.    * Use this function if you want the result of the encoding
  195.    * to be placed in another array and cut down the number of
  196.    * copy operation that have to be performed in the process.
  197.    * This is the preffered method for encoding binary data.
  198.    *
  199.    * NOTE: the output array is first reset and then resized
  200.    * appropriately before use, hence, all data stored in the
  201.    * output array will be lost.
  202.    *
  203.    * @param in   data to be uuencoded.
  204.    * @param out  uudecoded data.
  205.    */
  206.   static void uuencode( const QByteArray& in, QByteArray& out );
  207.  
  208.   /**
  209.    * Decodes the given data using the uudecode algorithm.
  210.    *
  211.    * Any 'begin' and 'end' lines like those generated by
  212.    * the utilities in unix and unix-like OS will be
  213.    * automatically ignored.
  214.    *
  215.    * @param in   data to be decoded.
  216.    * @return     decoded string.
  217.    */
  218.   static QCString uudecode( const QByteArray& in );
  219.  
  220.   /**
  221.    * @overload
  222.    *
  223.    * Same as the above functions except it accepts
  224.    * a null terminated string instead an array.
  225.    *
  226.    * @param str   string to be decoded.
  227.    * @return      uudecoded string.
  228.    */
  229.   static QCString uudecode( const QCString& str );
  230.  
  231.   /**
  232.    * Decodes the given data using the uudecode algorithm.
  233.    *
  234.    * Use this function if you want the result of the decoding
  235.    * to be placed in another array which cuts down the number
  236.    * of copy operation that have to be performed in the process.
  237.    * This is the preferred method for decoding binary data.
  238.    *
  239.    * Any 'begin' and 'end' lines like those generated by
  240.    * the utilities in unix and unix-like OS will be
  241.    * automatically ignored.
  242.    *
  243.    * NOTE: the output array is first reset and then resized
  244.    * appropriately before use, hence, all data stored in the
  245.    * output array will be lost.
  246.    *
  247.    * @param in   data to be decoded.
  248.    * @param out  uudecoded data.
  249.    */
  250.   static void uudecode( const QByteArray& in, QByteArray& out );
  251.  
  252.  
  253.   /**
  254.    * Encodes the given data using the base64 algorithm.
  255.    *
  256.    * The boolean argument determines if the encoded data is
  257.    * going to be restricted to 76 characters or less per line
  258.    * as specified by RFC 2045.  If @p insertLFs is true, then
  259.    * there will be 76 characters or less per line.
  260.    *
  261.    * @param in         data to be encoded.
  262.    * @param insertLFs  limit the number of characters per line.
  263.    *
  264.    * @return           base64 encoded string.
  265.    */
  266.   static QCString base64Encode( const QByteArray& in, bool insertLFs = false);
  267.  
  268.   /**
  269.    * @overload
  270.    *
  271.    * Same as the above functions except it accepts
  272.    * a null terminated string instead an array.
  273.    *
  274.    * @param str       string to be encoded.
  275.    * @param insertLFs limit the number of characters per line.
  276.    * @return          decoded string.
  277.    */
  278.   static QCString base64Encode( const QCString& str, bool insertLFs = false );
  279.  
  280.   /**
  281.    * Encodes the given data using the base64 algorithm.
  282.    *
  283.    * Use this function if you want the result of the encoding
  284.    * to be placed in another array which cuts down the number
  285.    * of copy operation that have to be performed in the process.
  286.    * This is also the preferred method for encoding binary data.
  287.    *
  288.    * The boolean argument determines if the encoded data is going
  289.    * to be restricted to 76 characters or less per line as specified
  290.    * by RFC 2045.  If @p insertLFs is true, then there will be 76
  291.    * characters or less per line.
  292.    *
  293.    * NOTE: the output array is first reset and then resized
  294.    * appropriately before use, hence, all data stored in the
  295.    * output array will be lost.
  296.    *
  297.    * @param in        data to be encoded.
  298.    * @param out       encoded data.
  299.    * @param insertLFs limit the number of characters per line.
  300.    */
  301.   static void base64Encode( const QByteArray& in, QByteArray& out,
  302.                             bool insertLFs = false );
  303.  
  304.   /**
  305.    * Decodes the given data that was encoded using the
  306.    * base64 algorithm.
  307.    *
  308.    * @param in   data to be decoded.
  309.    * @return     decoded string.
  310.    */
  311.   static QCString base64Decode( const QByteArray& in );
  312.  
  313.   /**
  314.    * @overload
  315.    *
  316.    * Same as the above functions except it accepts
  317.    * a null terminated string instead an array.
  318.    *
  319.    * @param str  string to be decoded.
  320.    * @return     decoded string.
  321.    */
  322.   static QCString base64Decode( const QCString& str );
  323.  
  324.   /**
  325.    * Decodes the given data that was encoded with the base64
  326.    * algorithm.
  327.    *
  328.    * Use this function if you want the result of the decoding
  329.    * to be placed in another array which cuts down the number
  330.    * of copy operation that have to be performed in the process.
  331.    * This is also the preferred method for decoding an encoded
  332.    * binary data.
  333.    *
  334.    * NOTE: the output array is first reset and then resized
  335.    * appropriately before use, hence, all data stored in the
  336.    * output array will be lost.
  337.    *
  338.    * @param in   data to be decoded.
  339.    * @param out  decoded data.
  340.    */
  341.   static void base64Decode( const QByteArray& in, QByteArray& out );
  342.  
  343.  
  344. private:
  345.   KCodecs();
  346.  
  347. private:
  348.   static const char UUEncMap[64];
  349.   static const char UUDecMap[128];
  350.   static const char Base64EncMap[64];
  351.   static const char Base64DecMap[128];
  352.   static const char hexChars[16];
  353.   static const unsigned int maxQPLineLength;
  354. };
  355.  
  356. class KMD5Private;
  357. /**
  358.  * @short An adapted C++ implementation of RSA Data Securities MD5 algorithm.
  359.  *
  360.  * The default constructor is designed to provide much the same
  361.  * functionality as the most commonly used C-implementation, while
  362.  * the other three constructors are meant to further simplify the
  363.  * process of obtaining a digest by calculating the result in a
  364.  * single step.
  365.  *
  366.  * KMD5 is state-based, that means you can add new contents with
  367.  * update() as long as you didn't request the digest value yet.
  368.  * After the digest value was requested, the object is "finalized"
  369.  * and you have to call reset() to be able to do another calculation
  370.  * with it.  The reason for this behavior is that upon requesting
  371.  * the message digest KMD5 has to pad the received contents up to a
  372.  * 64 byte boundary to calculate its value. After this operation it
  373.  * is not possible to resume consuming data.
  374.  *
  375.  * \b Usage:
  376.  *
  377.  * A common usage of this class:
  378.  *
  379.  * \code
  380.  * const char* test1;
  381.  * KMD5::Digest rawResult;
  382.  *
  383.  * test1 = "This is a simple test.";
  384.  * KMD5 context (test1);
  385.  * cout << "Hex Digest output: " << context.hexDigest().data() << endl;
  386.  * \endcode
  387.  *
  388.  * To cut down on the unnecessary overhead of creating multiple KMD5
  389.  * objects, you can simply invoke reset() to reuse the same object
  390.  * in making another calculation:
  391.  *
  392.  * \code
  393.  * context.reset ();
  394.  * context.update ("TWO");
  395.  * context.update ("THREE");
  396.  * cout << "Hex Digest output: " << context.hexDigest().data() << endl;
  397.  * \endcode
  398.  *
  399.  * @author Dirk Mueller <mueller@kde.org>, Dawit Alemayehu <adawit@kde.org>
  400.  */
  401.  
  402. class KDECORE_EXPORT KMD5
  403. {
  404. public:
  405.  
  406.   typedef unsigned char Digest[16];
  407.  
  408.   KMD5();
  409.  
  410.   /**
  411.    * Constructor that updates the digest for the given string.
  412.    *
  413.    * @param in   C string or binary data
  414.    * @param len  if negative, calculates the length by using
  415.    *             strlen on the first parameter, otherwise
  416.    *             it trusts the given length (does not stop on NUL byte).
  417.    */
  418.   KMD5(const char* in, int len = -1);
  419.  
  420.   /**
  421.    * @overload
  422.    *
  423.    * Same as above except it accepts a QByteArray as its argument.
  424.    */
  425.   KMD5(const QByteArray& a );
  426.  
  427.   /**
  428.    * @overload
  429.    *
  430.    * Same as above except it accepts a QCString as its argument.
  431.    */
  432.   KMD5(const QCString& a );
  433.  
  434.   /**
  435.    * Updates the message to be digested. Be sure to add all data
  436.    * before you read the digest. After reading the digest, you
  437.    * can <b>not</b> add more data!
  438.    *
  439.    * @param in     message to be added to digest
  440.    * @param len    the length of the given message.
  441.    */
  442.   void update(const char* in, int len = -1) { update(reinterpret_cast<const unsigned char*>(in), len); }
  443.  
  444.   /**
  445.    * @overload
  446.    */
  447.   void update(const unsigned char* in, int len = -1);
  448.  
  449.   /**
  450.    * @overload
  451.    *
  452.    * @param in     message to be added to the digest (QByteArray).
  453.    */
  454.   void update(const QByteArray& in );
  455.  
  456.   /**
  457.    * @overload
  458.    *
  459.    * @param in     message to be added to the digest (QCString).
  460.    */
  461.   void update(const QCString& in );
  462.  
  463.   /**
  464.    * @overload
  465.    *
  466.    * reads the data from an I/O device, i.e. from a file (QFile).
  467.    *
  468.    * NOTE that the file must be open for reading.
  469.    *
  470.    * @param file       a pointer to FILE as returned by calls like f{d,re}open
  471.    *
  472.    * @returns false if an error occurred during reading.
  473.    */
  474.   bool update(QIODevice& file);
  475.  
  476.   /**
  477.    * Calling this function will reset the calculated message digest.
  478.    * Use this method to perform another message digest calculation
  479.    * without recreating the KMD5 object.
  480.    */
  481.   void reset();
  482.  
  483.   /**
  484.    * @return the raw representation of the digest
  485.    */
  486.   const Digest& rawDigest ();
  487.  
  488.   /**
  489.    * Fills the given array with the binary representation of the
  490.    * message digest.
  491.    *
  492.    * Use this method if you do not want to worry about making
  493.    * copy of the digest once you obtain it.
  494.    *
  495.    * @param bin an array of 16 characters ( char[16] )
  496.    */
  497.   void rawDigest( KMD5::Digest& bin );
  498.  
  499.   /**
  500.    * Returns the value of the calculated message digest in
  501.    * a hexadecimal representation.
  502.    */
  503.   QCString hexDigest ();
  504.  
  505.   /**
  506.    * @overload
  507.    */
  508.   void hexDigest(QCString&);
  509.  
  510.   /**
  511.    * Returns the value of the calculated message digest in
  512.    * a base64-encoded representation.
  513.    */
  514.   QCString base64Digest ();
  515.  
  516.   /**
  517.    * returns true if the calculated digest for the given
  518.    * message matches the given one.
  519.    */
  520.   bool verify( const KMD5::Digest& digest);
  521.  
  522.   /**
  523.    * @overload
  524.    */
  525.   bool verify(const QCString&);
  526.  
  527. protected:
  528.   /**
  529.    *  Performs the real update work.  Note
  530.    *  that length is implied to be 64.
  531.    */
  532.   void transform( const unsigned char buffer[64] );
  533.  
  534.   /**
  535.    * finalizes the digest
  536.    */
  537.   void finalize();
  538.  
  539. private:
  540.   KMD5(const KMD5& u);
  541.   KMD5& operator=(const KMD5& md);
  542.  
  543.   void init();
  544.   void encode( unsigned char* output, Q_UINT32 *in, Q_UINT32 len );
  545.   void decode( Q_UINT32 *output, const unsigned char* in, Q_UINT32 len );
  546.  
  547.   Q_UINT32 rotate_left( Q_UINT32 x, Q_UINT32 n );
  548.   Q_UINT32 F( Q_UINT32 x, Q_UINT32 y, Q_UINT32 z );
  549.   Q_UINT32 G( Q_UINT32 x, Q_UINT32 y, Q_UINT32 z );
  550.   Q_UINT32 H( Q_UINT32 x, Q_UINT32 y, Q_UINT32 z );
  551.   Q_UINT32 I( Q_UINT32 x, Q_UINT32 y, Q_UINT32 z );
  552.   void FF( Q_UINT32& a, Q_UINT32 b, Q_UINT32 c, Q_UINT32 d, Q_UINT32 x,
  553.                Q_UINT32  s, Q_UINT32 ac );
  554.   void GG( Q_UINT32& a, Q_UINT32 b, Q_UINT32 c, Q_UINT32 d, Q_UINT32 x,
  555.                 Q_UINT32 s, Q_UINT32 ac );
  556.   void HH( Q_UINT32& a, Q_UINT32 b, Q_UINT32 c, Q_UINT32 d, Q_UINT32 x,
  557.                 Q_UINT32 s, Q_UINT32 ac );
  558.   void II( Q_UINT32& a, Q_UINT32 b, Q_UINT32 c, Q_UINT32 d, Q_UINT32 x,
  559.              Q_UINT32 s, Q_UINT32 ac );
  560.  
  561. private:
  562.   Q_UINT32 m_state[4];
  563.   Q_UINT32 m_count[2];
  564.   Q_UINT8 m_buffer[64];
  565.   Digest m_digest;
  566.   bool m_finalized;
  567.  
  568.   KMD5Private* d;
  569. };
  570.  
  571. /**
  572.  * @short An adapted C++ implementation of the MD4 Message-Digest algorithm.
  573.  * @since 3.4
  574.  *
  575.  * The class usage is the same as KMD5.
  576.  */
  577. class KDECORE_EXPORT KMD4
  578. {
  579. public:
  580.  
  581.   typedef unsigned char Digest[16];
  582.  
  583.   KMD4();
  584.  
  585.   /**
  586.    * Constructor that updates the digest for the given string.
  587.    *
  588.    * @param in   C string or binary data
  589.    * @param len  if negative, calculates the length by using
  590.    *             strlen on the first parameter, otherwise
  591.    *             it trusts the given length (does not stop on NUL byte).
  592.    */
  593.   KMD4(const char* in, int len = -1);
  594.  
  595.   /**
  596.    * @overload
  597.    *
  598.    * Same as above except it accepts a QByteArray as its argument.
  599.    */
  600.   KMD4(const QByteArray& a );
  601.  
  602.   /**
  603.    * @overload
  604.    *
  605.    * Same as above except it accepts a QCString as its argument.
  606.    */
  607.   KMD4(const QCString& a );
  608.  
  609.   /**
  610.    * Updates the message to be digested. Be sure to add all data
  611.    * before you read the digest. After reading the digest, you
  612.    * can <b>not</b> add more data!
  613.    *
  614.    * @param in     message to be added to digest
  615.    * @param len    the length of the given message.
  616.    */
  617.   void update(const char* in, int len = -1) { update(reinterpret_cast<const unsigned char*>(in), len); }
  618.  
  619.   /**
  620.    * @overload
  621.    */
  622.   void update(const unsigned char* in, int len = -1);
  623.  
  624.   /**
  625.    * @overload
  626.    *
  627.    * @param in     message to be added to the digest (QByteArray).
  628.    */
  629.   void update(const QByteArray& in );
  630.  
  631.   /**
  632.    * @overload
  633.    *
  634.    * @param in     message to be added to the digest (QCString).
  635.    */
  636.   void update(const QCString& in );
  637.  
  638.   /**
  639.    * @overload
  640.    *
  641.    * reads the data from an I/O device, i.e. from a file (QFile).
  642.    *
  643.    * NOTE that the file must be open for reading.
  644.    *
  645.    * @param file       a pointer to FILE as returned by calls like f{d,re}open
  646.    *
  647.    * @returns false if an error occurred during reading.
  648.    */
  649.   bool update(QIODevice& file);
  650.  
  651.   /**
  652.    * Calling this function will reset the calculated message digest.
  653.    * Use this method to perform another message digest calculation
  654.    * without recreating the KMD4 object.
  655.    */
  656.   void reset();
  657.  
  658.   /**
  659.    * @return the raw representation of the digest
  660.    */
  661.   const Digest& rawDigest ();
  662.  
  663.   /**
  664.    * Fills the given array with the binary representation of the
  665.    * message digest.
  666.    *
  667.    * Use this method if you do not want to worry about making
  668.    * copy of the digest once you obtain it.
  669.    *
  670.    * @param bin an array of 16 characters ( char[16] )
  671.    */
  672.   void rawDigest( KMD4::Digest& bin );
  673.  
  674.   /**
  675.    * Returns the value of the calculated message digest in
  676.    * a hexadecimal representation.
  677.    */
  678.   QCString hexDigest ();
  679.  
  680.   /**
  681.    * @overload
  682.    */
  683.   void hexDigest(QCString&);
  684.  
  685.   /**
  686.    * Returns the value of the calculated message digest in
  687.    * a base64-encoded representation.
  688.    */
  689.   QCString base64Digest ();
  690.  
  691.   /**
  692.    * returns true if the calculated digest for the given
  693.    * message matches the given one.
  694.    */
  695.   bool verify( const KMD4::Digest& digest);
  696.  
  697.   /**
  698.    * @overload
  699.    */
  700.   bool verify(const QCString&);
  701.  
  702. protected:
  703.   /**
  704.    *  Performs the real update work.  Note
  705.    *  that length is implied to be 64.
  706.    */
  707.   void transform( Q_UINT32 buf[4], Q_UINT32 const in[16] );
  708.  
  709.   /**
  710.    * finalizes the digest
  711.    */
  712.   void finalize();
  713.  
  714. private:
  715.   KMD4(const KMD4& u);
  716.   KMD4& operator=(const KMD4& md);
  717.  
  718.   void init();
  719.  
  720.   void byteReverse( unsigned char *buf, Q_UINT32 len );
  721.  
  722.   Q_UINT32 rotate_left( Q_UINT32 x, Q_UINT32 n );
  723.   Q_UINT32 F( Q_UINT32 x, Q_UINT32 y, Q_UINT32 z );
  724.   Q_UINT32 G( Q_UINT32 x, Q_UINT32 y, Q_UINT32 z );
  725.   Q_UINT32 H( Q_UINT32 x, Q_UINT32 y, Q_UINT32 z );
  726.   void FF( Q_UINT32& a, Q_UINT32 b, Q_UINT32 c, Q_UINT32 d, Q_UINT32 x,
  727.                Q_UINT32  s );
  728.   void GG( Q_UINT32& a, Q_UINT32 b, Q_UINT32 c, Q_UINT32 d, Q_UINT32 x,
  729.                 Q_UINT32 s );
  730.   void HH( Q_UINT32& a, Q_UINT32 b, Q_UINT32 c, Q_UINT32 d, Q_UINT32 x,
  731.                 Q_UINT32 s );
  732.  
  733. private:
  734.   Q_UINT32 m_state[4];
  735.   Q_UINT32 m_count[2];
  736.   Q_UINT8 m_buffer[64];
  737.   Digest m_digest;
  738.   bool m_finalized;
  739.  
  740.   class KMD4Private;
  741.   KMD4Private* d;
  742. };
  743.  
  744.  
  745. #endif
  746.